package com.bxs.handler;

import com.bxs.dao.BaseDataHandler;
import org.pcap4j.core.PacketListener;
import org.pcap4j.core.PcapDumper;
import org.pcap4j.core.PcapPacket;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dream
 * @title: AHandlerManager
 * @projectName ids_v0_2
 * @description: TODO
 */
// 包预处理管理器
public class HandlerManager{
    // 数据包处理器类，对数据包进行日志记录等
    protected List<BasePacketHandler> handlers = new ArrayList<>();

    // dumper
    public PcapDumper packetDumper = null;

    public HandlerManager(PcapDumper dumper){
        packetDumper = dumper;
    }

    public void execute(PcapPacket packet){
        for (BasePacketHandler handler: handlers){
            handler.handle(packet);
        }
    }

    // 注册新的包处理器
    public void register(BasePacketHandler packetHandler){
        handlers.add(packetHandler);
    }

    //
    public List<BasePacketHandler> getHandlers(){
        return this.handlers;
    }
}
